/**
 * 
 */
package com.tvshows.front.listener.command;

import com.tvshows.front.controllers.dialog.ActionsController;
import com.tvshows.front.listener.command.interfaces.FavoriteCommand;
import com.tvshows.front.ui.favorite.UpsideCompositeFavoriteUI;
import com.tvshows.front.view.favorite.UpsideCompositeFavoriteView;
import com.tvshows.interactions.ObserverBdd;
import com.tvshows.structure.bdd.BddQueries;

/**
 * @author Tangi Midy
 */
public class DeleteFavoriteCommand
    extends FavoriteCommand
{

    /**
     * The {@link UpsideCompositeFavoriteView}
     */
    private UpsideCompositeFavoriteUI upsideComposite;

    /**
     * @param upsideComposite
     */
    public DeleteFavoriteCommand( UpsideCompositeFavoriteUI upsideComposite )
    {
        this.upsideComposite = upsideComposite;
    }

    /**
     * @see com.tvshows.front.listener.command.interfaces.FavoriteCommand#executeCommand()
     */
    @Override
    public void executeCommand()
    {
        if ( !ObserverBdd.getObserverBdd().getSelectedFavorite().equals( "NoSelection" ) )
        {
            if ( !BddQueries.getBddQueries().isJobRunning() )
            {
                BddQueries.getBddQueries().deleteFavorite( ObserverBdd.getObserverBdd().getSelectedFavorite() );
                ObserverBdd.getObserverBdd().activeDeleteOnFavorite();
                ObserverBdd.getObserverBdd().reloadListFavorite();
            }
            else
            {
                ActionsController.popUpJobRunning( upsideComposite );
            }
        }
    }

}
